package com.huangwenshuo.futurestarschoolmanagement.controller;


import com.huangwenshuo.futurestarschoolmanagement.pojo.dto.CoursewareDto;
import com.huangwenshuo.futurestarschoolmanagement.pojo.dto.WorkDto;
import com.huangwenshuo.futurestarschoolmanagement.pojo.enums.RequestStateEnum;
import com.huangwenshuo.futurestarschoolmanagement.pojo.vo.Result;
import com.huangwenshuo.futurestarschoolmanagement.service.CoursewareService;
import com.huangwenshuo.futurestarschoolmanagement.utils.ResUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author huangwenshuo
 * @since 2021-03-07
 */
@RestController
@RequestMapping("/courseware")
public class CoursewareController {

    @Autowired
    private CoursewareService coursewareService;

    @GetMapping("getFlies")
    public Result getFlies(CoursewareDto.CPage page){
        Map<String,Object> res = new HashMap<>();
        try {
            res = coursewareService.getFlies(page);
        } catch (Exception e) {
            e.printStackTrace();
            return ResUtils.result(RequestStateEnum.FAILED.value(), "" + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(),res,"添加成功");
    }

    @GetMapping("addFiles")
    public Result addFiles(CoursewareDto.CPage page){
        try {
            coursewareService.addFiles(page);
        } catch (Exception e) {
            e.printStackTrace();
            return ResUtils.result(RequestStateEnum.FAILED.value(), "" + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(),"添加成功");
    }

    @GetMapping("updateFile")
    public Result updateFile(CoursewareDto.CPage page){
        try {
            coursewareService.updateFile(page);
        } catch (Exception e) {
            e.printStackTrace();
            return ResUtils.result(RequestStateEnum.FAILED.value(), "" + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(),"更新成功");
    }

    @GetMapping("delFile")
    public Result delFile(CoursewareDto.CPage page){
        try {
            coursewareService.delFile(page);
        } catch (Exception e) {
            e.printStackTrace();
            return ResUtils.result(RequestStateEnum.FAILED.value(), "" + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(),"删除成功");
    }



}

